<?php
    require "sql.php";
    $data=array(
        array(
            'code'=>0    
        ),
        array(
            'code'=>1
        ),
        array(
            'code'=>2
        ),
        array(
            'code'=>3
        )
    );
    $user['name']=$_POST['name'];
    $user['email']=$_POST['email'];
    $user['pass']=md5($_POST['password']);

    $str1="select * from user where email = '".$user['email']."'";
    $str4="select * from user where name = '".$user['name']."'";
    $str2="insert into user(name,passwords,email) values('".$user['name']."','".$user['pass']."','".$user['email']."')";

    $result1=$conn->query($str4);
    $result2=$conn->query($str1);
    if ($result1->num_rows > 0) {
        echo json_encode($data[0]);       
    }else if($result2->num_rows > 0){
        echo json_encode($data[1]);
    }else if($conn->query($str2)===true){
        $str3="insert into log(log_name,log_time,log_kind) values('".$user['name']."','".date('Y-m-d H:i:s')."','账户注册')";
        $conn->query($str3);
        echo json_encode($data[2]);
    }else{
        echo json_encode($data[3]);
    };
    $conn->close();
?>